<template>
  <div id="groupList">
    <el-dialog title="群发名单" :visible.sync="sendList" width="900px">
      <div class="dialog-in">
        <el-table :data="gridData" stripe size="mini" @selection-change="sendingList">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column property="owner" label="业主" width="80"></el-table-column>
          <el-table-column property="owner_phone" label="手机号" width="120"></el-table-column>
          <el-table-column property="address" label="物业地址"></el-table-column>
          <el-table-column property="time" label="服务时间" width="180"></el-table-column>
          <el-table-column property="servicer" label="管家姓名" width="80"></el-table-column>
          <el-table-column property="servicer_phone" label="管家手机号" width="120"></el-table-column>
          <el-table-column property="status" label="发送状态" width="120"></el-table-column>
        </el-table>
        <el-button type="primary" size="mini" @click="sendSMS">服务时间通知</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// var urls="http://192.168.1.52:8802";
export default {
  data() {
    return {
      gridData: [
        // {
        //   date: "2016-05-02 12:00:20",
        //   owner: "业主姓名",
        //   housekeeperName: "管家姓名",
        //   housekeeperPhone: "152******84",
        //   phone: "15268095284",
        //   address: "上海市普陀区金沙江路 1518 弄"
        // }
      ],
      sendList: false,
      multipleSelection:[],
      dataId:''
    };
  },
  created() {
    let that=this
    this.$root.$on("sendList", data => {
      that.sendList = true;
      that.dataId=data
      that.ajaxList()
      })
  },
  methods:{
    sendSMS(){  //发送短信
      let that=this
      let list=this.multipleSelection
      if(list.length<=0){
        this.$message({
          message: '请先选择发送短信的业主！',
          type: 'warning'
        });
      }else{
        let ids=""
        for(let i=0,len=list.length;i<len;i++){
          if(i==list.length-1){
            ids+=list[i].id
          }else{
            ids+=list[i].id+'-'
          }
        }
        console.log(ids)
        let url="/api/sms/orderSms/sendSms?ids="+ids;
        this.$http({
            url: url,
            method: "POST",
          })
            .then(res => {
              if(res.data.status==200){
                that.$message({
                  message: '短信发送成功！',
                  type: 'success'
                });
                that.ajaxList()
              }else{
                that.$message.error('短信发送失败！'+res.data.status);
              }
            })
            .catch(error => {
              that.$message.error('短信发送失败！');
            });
      }
      
    },
    sendingList(val){  //多选框选中
      this.multipleSelection = val;
    },
    ajaxList(){   //列表请求
      let that = this;
      let data=that.dataId
      let url="/api/sms/orderSmsLog/queryInfo?id="+data
      this.$http({
            url: url,
            method: "GET",
            data: {}
          })
            .then(res => {
              let data=res.data.info
              console.log(data)
              for(let i=0,len=data.length;i<len;i++){
                data[i].status=='1'?data[i].status='已发送':data[i].status='未发送'
              }
              that.gridData=data
            })
            .catch(error => {
              console.log(error);
            });
    }
  }
};
</script>
<style lang="less" scoped>
#groupList {
  overflow: hidden;
  .dialog-in {
    overflow: hidden;
    .el-button {
      float: right;
      margin-top: 20px;
      margin-bottom: 20px;
    }
  }
  .el-dialog{
    padding-bottom: 20px !important;
  }
}
</style>


